<?php

namespace App\Controller\User;


use App\Controller\BaseController;
use App\Exception\MessageException;
use App\Model\GreetMaster;
use App\Request\User\GreetMasterDeleteRequest;
use App\Request\User\GreetMasterEditRequest;
use App\Services\User\GreetMasterService;
use App\Utils\RedisClient;
use Hyperf\Context\Context;
use Hyperf\Di\Annotation\Inject;

class GreetMasterController extends BaseController
{

    #[Inject]
    public GreetMasterService $greetMasterService;


    /**
     * Note - 女用户获取打招呼列表
     * DateTime 2024/8/20 11:44
     * User Admin
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function getGreetingList()
    {
        $userInfo = Context::get('user');
        $is_choose = $this->request->post('is_choose', 0);
        $result = $this->greetMasterService->getGreetingList($userInfo, $is_choose);
        return $this->return($result);
    }

    /**
     * Note - 女用户编辑打招呼
     * DateTime 2024/8/20 11:44
     * User Admin
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function edit(GreetMasterEditRequest $request)
    {
        $userInfo = Context::get('user');
        $params = $this->request->post();
        $request->execute($params);
        if ($userInfo['sex'] == 1) {
            throw new MessageException('网络波动');
        }
        $result = $this->greetMasterService->edit($userInfo['id'], $params);
        return $this->return($result);

    }

    /**
     * Note - 女用户删除打招呼
     * DateTime 2024/8/20 11:44
     * User Admin
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function delete(GreetMasterDeleteRequest $request)
    {
        $params = $this->request->post();
        $request->execute($params);
        $userInfo = Context::get('user');
        $master_id = $params['master_id'];
        //如果是男性
        if ($userInfo['sex'] == 1) {
            throw new MessageException('网络波动');
        }
        $rs = GreetMaster::query()->where('uid', $userInfo['id'])->where('id', $master_id)->delete();
        if (!$rs) {
            throw new MessageException("操作失败");
        }
        return $this->return();

    }

    /**
     * Note - 女用户设置快捷打招呼模板
     * DateTime 2024/8/20 14:11
     * User Admin
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function settingGreet()
    {
        $userInfo = Context::get('user');
        $uid = $userInfo['id'];
        $ids = $this->request->post('greets', 0);
        //如果是男性
        if ($userInfo['sex'] == 1) {
            throw new MessageException('网络波动');
        }
        $result = $this->greetMasterService->settingGreet($uid, $ids);
        return $this->return($result);
    }

}